<%@page import="org.springframework.security.core.context.SecurityContextHolder"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="org.apache.commons.lang.time.DateFormatUtils"%>
<%@page import="org.springframework.util.CollectionUtils"%>
<%@page import="java.util.Collection"%>
<%@ include file="../common/common_include.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	AppForm form = (AppForm)request.getAttribute("command");
	UserInfo user = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	String username = user.getName();
	TblApiApp app = (TblApiApp)request.getAttribute("app");
%>

<div>
	<form id="BarAddForm" target="_coreIframe" method="post" action="<%=request.getContextPath()%>/app/doEdit" enctype="multipart/form-data">
		<input type="hidden" name="id" value="<%=EncrypTool.encode(app.getId()) %>">
		<div class="breadcrumb">
			<div class="bcIcon"></div>
			<ul class="bcNav">
				<li>编辑APP</li>
			</ul>
		</div>
		<table class="formTable">
			<tr>
				<td class="tdTitle">厂商名称：</td>
				<td>
					<select id="companyName" class="easyui-combobox" value="<%=app.getCompany()%>" name="companyName" style="width:200px;" >
				</td>
				<span class="errorTipWrap" id="errorTip_companyName"></span>
			</tr>
			<tr>
				<td class="tdTitle">操作系统：</td>
				<td>
					<select id="appOS" class="easyui-combobox" name="appOS" style="width:200px;"></select>
				</td>
				<span class="errorTipWrap" id="errorTip_appOS"></span>
			</tr>
			<tr>
				<td class="tdTitle">应用类型：</td>
				<td>
					<select id="appType" class="easyui-combobox" name="appType" style="width:200px;"></select>
				</td>
				<span class="errorTipWrap" id="errorTip_appType"></span>
			</tr>
			<tr>
				<td class="tdTitle">版本号：</td>
				<td>
					<input class="inputText xs" type="text"  value="<%=app.getAppVersion() %>" name="appVersion">
				</td>
				<span class="errorTipWrap" id="errorTip_appVersion"></span>
			</tr>
			
			<tr>
				<td class="tdTitle">使用状态：</td>
				<td>
					<select id="appStatus" class="easyui-combobox" name="appStatus" style="width:200px;"></select>
					<span class="errorTipWrap" id="errorTip_appStatus"></span>	
				</td>
			</tr>
			
			<tr>	
				<td class="tdTitle">文件：</td>
				<td>
					<input type="file" id="multipartFile">
					<span class="uploadResultLabel" id="uploadResultLabel" style="display: inline-block;">
						<%=StringUtils.isNotBlank(app.getAppDir())?app.getAppDir():""%>
					</span>
					<div>
						<span class="uploadTip">只能上传exe,apk格式的文件</span>
					</div>
					<input type="hidden" name="tempFileId" value="">
				</td>
			</tr>
			
			<tr>
				<td class="tdTitle"></td>
				<td>
					<div>
						<input class="input-btn-microsoft" type="submit" value="提交">
						<a class="a-btn-microsoft" href="">取消</a>
					</div>
				</td>
			</tr>	
		</table>
	</form>
	<iframe id="_coreIframe" name="_coreIframe" style="display: none;"></iframe>
</div>
<script type="text/javascript">
	$('#companyName').combobox({
		url:global.contextPath + '/app/getBrand',
		valueField:'id',
		textField:'type'
	});
	$('#companyName').combobox('select', '<%=app.getCompany()%>');
	
	$('#appOS').combobox({
		url:global.contextPath + '/app/getOS',
		valueField:'id',
		textField:'type',
		onLoadSuccess: function () { 
            var val = $(this).combobox("getData");
	 		for(var i=0;i<val.length;i++){
	 			if(val[i].id==parseInt('<%=app.getAppOs()%>')){
	 				$(this).combobox("setValue", val[i].type);
	 			}
	 		}
        }
	});
	$('#appOS').combobox('select', '<%=app.getAppOs()%>');
	
	$('#appType').combobox({
		url:global.contextPath + '/app/getAPPType',
		valueField:'id',
		textField:'type',
		onLoadSuccess: function () { 
            var val = $(this).combobox("getData");
	 		for(var i=0;i<val.length;i++){
	 			if(val[i].id==parseInt('<%=app.getType()%>')){
	 				$(this).combobox("setValue", val[i].type);
	 				$(this).combobox('select', val[i].id);
	 			}
	 		}
        }
	});
	$('#appType').combobox('select', '<%=app.getType()%>');
	
	$('#appStatus').combobox({
		url:global.contextPath + '/app/getStatusType',
		valueField:'id',
		textField:'type',
	 	onLoadSuccess: function () { //加载完成后,设置选中第一项
            var val = $(this).combobox("getData");
	 		for(var i=0;i<val.length;i++){
	 			if(val[i].id==parseInt('<%=app.getStatus()%>')){
	 				$(this).combobox("setValue", val[i].type);
	 				$(this).combobox('select', val[i].id);
	 			}
	 		}
        }
	});	
	
</script>
<script type="text/javascript">
	$(function() {
		$("input[name=videoTitle]").focus();
		_uploadFile("multipartFile","<%=request.getSession().getId()%>");
	    function _uploadFile(id,sid){
			$("#"+id).uploadify({
		        auto: true,
		        multi:false,
		        fileExt:'*.mp4;*.f4v;*.flv',
		        uploader: global.contextPath + "/servlet/upload?jsessionid="+sid,
		        swf: global.contextPath + '/js/jplugin/uploadify/uploadify.swf',
		        onUploadSuccess:function(file, data, response){
		        	var fileName = file.name;
		        	var data = JSON.parse(data);
		        	if(data['status']=='0'){
		        		$("#uploadResultLabel").html(fileName);
		        		$("input[name=tempFileId]").val(data['fileId']);
		        		var nameEle = $("input[name=name]");
		        		if(nameEle.val()==""){
		        			nameEle.val(fileName);
		        		}
		        	}else if(data['status']=='1'){
		        		var s = "上传失败："+data['errorMessage'];
		        		$("#uploadResultLabel").html("<span style='color:#ff0000'>"+s+"</span>");
		        	}
		        }
		    });
	    };
	    $("#up").uploadPreview({ Img: "imgPreview", Width: 98, Height: 66 });
	}); 
</script>



